library CachedFunctionSystem

	globals
		private hashtable ht = InitHashtable()
	endglobals
	
	function RegisterFunction takes string name, code c returns nothing
		local trigger t = CreateTrigger()
		call TriggerAddAction(t, c)
		call SaveTriggerHandle(ht, StringHash(name), 0, t)
	endfunction

	function ExecuteRegisteredFunction takes string name returns nothing
		local trigger t = null
		if HaveSavedHandle(ht, StringHash(name),0) then
			set t = LoadTriggerHandle(ht, StringHash(name),0)
			if t != null then
				call TriggerExecute(t)
				set t = null
				return
			endif
		endif
		call BJDebugMsg("unable to find function " + name)
	endfunction
	
endlibrary